<template>
    <div class="task">
        <div class="bg">
            <div class="logo" @click="toHome">
                <img src="../../assets/logo.png" alt="">
                <div>
                    任务中心
                </div>
            </div>
        </div>
        <div class="search">
            <el-form ref="ruleForm" :model="TaskTableDataQuery" :inline="true" class="demo-form-inline"
                label-width="120px">
                <el-form-item label="请输入任务名称" prop="title">
                    <el-input v-model="TaskTableDataQuery.title" clearable></el-input>
                </el-form-item>
                <el-form-item label="处理时间范围" class="time-span">
                    <el-date-picker type="date" value-format="yyyy-MM-dd" v-model="TaskTableDataQuery.startDate">
                    </el-date-picker>
                    -
                    <el-date-picker type="date" value-format="yyyy-MM-dd" v-model="TaskTableDataQuery.endDate">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="类型">
                    <div class="flow-status">
                        <span @click="onChangeStatus(index)" :class="flowIndex == index ? 'active' : ''"
                            v-for="(item, index) in flowStatus" :key="index">{{ item }}</span>
                    </div>
                </el-form-item>
                <el-form-item label="">
                    <el-button type="primary" icon="el-icon-refresh" @click="resetForm('ruleForm')">重置</el-button>
                    <el-button @click="onSearch" type="primary" icon="el-icon-search">查询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="content">
            <div class="list">
                <div class="item" @click="toTaskDetail(item)" v-for="item in taskList" :key="item.id">
                    <div class="top">
                        <div class="left">
                            <span class="no-dot" v-if="item.hasRead"></span>
                            <span class="dot" v-else></span>
                            {{ item.title }}
                        </div>
                        <!-- <div class="right">
                            <span>流程图</span>
                            <span>流转记录</span>
                        </div> -->
                    </div>
                    <div class="bottom">
                        <div class="left">
                            <span>发起人：{{ item.creatorName }}</span>
                            <span class="status">流程状态：<span>{{ item.status }}</span></span>
                        </div>
                        <div class="right">
                            <span>时间:{{ item.createdAt.slice(0, 10) }}</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="pagination">
                <el-pagination :background="true" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page.sync="currentPage" :page-size="10" layout="total, prev, pager, next" :total="50">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { TaskTableData } from "@/api/task";
import { msgStatusChange } from "@/api/message";

export default {
    name: 'NotificationAnnouncement',
    data() {
        return {
            noticIndex: 0,
            noticTitle: "全部通知",
            noticClassify: ["全部通知", "公告通知", "会议通知", "院内通知", "党字公文", "其他公文"],
            currentPage: 1,
            flowIndex: 0,
            flowStatus: ["待办任务", "已办任务", "我发起的"],
            taskList: [],
            TaskTableDataQuery: {
                startDate: "",
                endDate: "",
                title: "",
                assignedTo: localStorage.getItem("userId"),//指派人id
                // createdBy: "",//创建人id
                status: 2//  任务状态 ('待开始1', '进行中2', '已完成3', '已取消4') 
            },
        }
    },
    mounted() {
        this.getTaskTableData();
    },
    methods: {
        toTaskDetail(item) {
            if (!item.hasRead) {
                // 修改通知已读状态
                msgStatusChange({
                    msgId: item.id,
                    rcvUserId: localStorage.getItem("userId"),
                    types: "待办消息",
                    msgCreatedDate: item.createdAt

                }).then(res => {
                    console.log(res)
                })
            }
            window.open(item.jzUrl, '_blank');
        },
        //获取任务中心数据
        getTaskTableData() {
            TaskTableData(this.TaskTableDataQuery).then(res => {
                this.taskList = res.data;
            })
        },
        //重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.TaskTableDataQuery.startDate = "";
            this.TaskTableDataQuery.endDate = "";
        },
        onSearch() {
            this.getTaskTableData(this.TaskTableDataQuery);
        },
        toHome() {
            this.$router.push("/teacher")
        },
        handleSizeChange() {

        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        },
        onChangeStatus(index) {
            console.log(index)
            this.flowIndex = index;
            if (index == 0) {
                this.TaskTableDataQuery = {
                    types: "待办",
                    assignedTo: localStorage.getItem("userId"),
                    status: 2
                }
            } else if (index == 1) {
                this.TaskTableDataQuery = {
                    types: "待办",
                    assignedTo: localStorage.getItem("userId"),
                    status: 3
                }
            } else {
                this.TaskTableDataQuery = {
                    types: "待办",
                    createdBy: localStorage.getItem("userId"),//创建人id
                }
            }
            this.getTaskTableData();
        }
    }
}
</script>

<style lang="scss" scoped>
.task {
    .bg {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 110px;
        z-index: 999;
        background: url("../../assets/notic-bg.jpg") no-repeat;

        .logo {
            padding: 10px 40px;
            display: flex;
            align-items: center;

            &>div {
                color: white;
                margin-left: 10px;
                border-left: 1px solid white;
                padding: 14px 0;
                padding-left: 15px;
            }
        }
    }

    .search {
        width: 1200px;
        margin-left: auto;
        margin-right: auto;
        margin-top: 130px;
        display: flex;
        flex-wrap: wrap;
        border: 1px solid rgba(0, 0, 0, .1);
        padding: 20px;
        box-sizing: border-box;

        .el-form {
            display: flex;
            flex-wrap: wrap;

            .el-form-item {
                width: 50%;
                margin-right: 0;
                display: flex;

                :deep .el-form-item__content {
                    flex: 1;
                }

                .el-select,
                .el-date-editor {
                    width: 100%;
                }
            }

            .time-span {
                :deep .el-form-item__content {
                    display: flex
                }
            }

            .flow-status {
                span {
                    padding: 5px;
                    margin-right: 10px;

                    &.active {
                        background-color: #2196F3;
                        color: white;
                    }
                }
            }
        }

        .search-btn {
            text-align: right;
            display: flex;
            width: 100%;
            justify-content: flex-end;
        }
    }

    .content {
        max-height: calc(100vh - 122px);
        width: 1200px;
        margin-left: auto;
        margin-right: auto;
        margin-top: 40px;
        margin-bottom: 30px;

        .list {
            .item {
                color: #333;
                padding-bottom: 20px;
                margin-bottom: 20px;
                transition: all .3s ease-in-out;
                border-bottom: 1px dashed rgba(0, 0, 0, .1);

                .top {
                    display: flex;
                    justify-content: space-between;
                    margin-bottom: 15px;

                    .left {
                        color: #333333;
                        font-weight: bold;

                        .dot,
                        .no-dot {
                            display: inline-block;
                            width: 5px;
                            height: 5px;
                            background-color: red;
                            border-radius: 50%;
                            margin-left: 8px;
                            vertical-align: middle;
                        }

                        .no-dot {
                            background-color: #acaebc;
                        }
                    }

                    .right {
                        color: #2196F3;
                        font-size: 14px;

                        span:first-child {
                            margin-right: 10px;
                        }
                    }
                }

                .bottom {
                    display: flex;
                    justify-content: space-between;
                    font-size: 14px;
                    color: #333333;

                    .left {
                        span:first-child {
                            margin-right: 20px;
                        }

                        .status {
                            span {
                                color: #6DB773;
                            }
                        }
                    }
                }
            }
        }

        .pagination {
            margin-top: 10px;

            .el-pagination {
                text-align: right;
            }
        }
    }
}
</style>